package icu.d4peng.basic.core.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import icu.d4peng.basic.core.exception.JsonParseException;
import icu.d4peng.basic.core.json.JacksonMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * JackJsonUtil:jackson工具类
 *
 * @author d4peng <a href="d4peng@qq.com">d4peng@qq.com</a>
 * @since 2023.12.02
 */
public class JacksonUtil {

	private static final Logger LOGGER = LoggerFactory.getLogger(JacksonUtil.class);

	private JacksonUtil() {
	}

	private static JacksonMapper getInstance() {
		return new JacksonMapper();
	}

	public static <T> String toJson(T value) {
		try {
			return getInstance().writeValueAsString(value);
		}
		catch (JsonProcessingException e) {
			LOGGER.info(e.getMessage(), e.getCause());
			throw new JsonParseException();
		}
	}

}
